package com.ybxx.asset.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.ybxx.asset.dao.InstrumentDao;
import com.ybxx.asset.model.Instrument;
import com.ybxx.asset.service.InstrumentService;
import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.dao.GenericDao;
import com.ybxx.core.service.impl.BaseServiceImpl;
import com.ybxx.core.web.paging.PagingBean;

public class InstrumentServiceImpl extends BaseServiceImpl<Instrument>
		implements InstrumentService {
	private InstrumentDao instrumentDao;
	public InstrumentServiceImpl(InstrumentDao dao) {
		super(dao);
		this.instrumentDao=dao;
		// TODO Auto-generated constructor stub
	}
	public List<Instrument> queryPage(Instrument instrument, QueryFilter filter) {
		String hql="from Instrument i where 1=1 ";
		if(instrument!=null && StringUtils.isNotEmpty(instrument.getIname())){
			hql+=" and i.iname like '%"+instrument.getIname()+"%'";
		}
		if(instrument!=null && StringUtils.isNotEmpty(instrument.getUnit())){
			hql+=" and i.unit like '%"+instrument.getUnit()+"%'";
		}
		if(instrument!=null && StringUtils.isNotEmpty(instrument.getAddr())){
			hql+=" and i.addr like '%"+instrument.getAddr()+"%'";
		}
		
		return instrumentDao.findByHql(hql, null, filter.getPagingBean());
	}
	public List<Instrument> exportExcel_Print(Instrument instrument) {
		String hql="from Instrument i left join fetch i.company c where 1=1 ";
		if(instrument!=null && StringUtils.isNotEmpty(instrument.getIname())){
			hql+=" and i.iname like '%"+instrument.getIname()+"%'";
		}
		if(instrument!=null && StringUtils.isNotEmpty(instrument.getUnit())){
			hql+=" and i.unit like '%"+instrument.getUnit()+"%'";
		}
		if(instrument!=null && StringUtils.isNotEmpty(instrument.getAddr())){
			hql+=" and i.addr like '%"+instrument.getAddr()+"%'";
		}
		
		return instrumentDao.findByHql(hql, null);
	}
	@Override
	public Instrument get(String id) {
		String hql="from Instrument i left join fetch i.company c where icode='"+id+"' ";
		return (Instrument)instrumentDao.findUnique(hql, null);
	}

}
